--[[/**
-- * 
 * 伤害转化为护盾值
 * [0] n 万分比
-- */]]

---@class BuffEffect384101 : BaseBuffEffect
BuffEffect384101 = ClientFight.CreateClass("BuffEffect384101", ClientFight.BaseBuffEffect)
local t = BuffEffect384101

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local source = buff.source;
    local parameters = {...};
    if (table.getn(parameters) < 3) then
    return IBuffEffect.FAIL;
    end
    if not parameters[3]then
    return IBuffEffect.FAIL;
    end
    local result = parameters[3];
    if (not result:isDamage())then
    return IBuffEffect.FAIL;
    end
    if (not AttackUtils.isDamage(result.state))then
    return IBuffEffect.FAIL;
    end
    --
    local buffEffectValue = buff.buffBean.f_BuffEffectValue;
    local addHp = (result.damage * Utils.toRatio(buffEffectValue[1]));
    if (addHp <= 0)then
    return IBuffEffect.FAIL;
    end
    local owner = buff.target;
    local buffModelId = buffEffectValue[2];--护盾的buffid
    local defeatBuff = BuffManager.getBuffByModel(owner, buffModelId);
    if (defeatBuff == nil)then
    return IBuffEffect.FAIL;
    end
    if (defeatBuff.pool.type ~= BuffPoolEnum.DEFEAT)then
    return IBuffEffect.REMOVE;
    end
    defeatBuff.pool.setCurrent(defeatBuff.pool.current + addHp,defeatBuff);
    if (defeatBuff.pool.max < defeatBuff.pool.current) then
    defeatBuff.pool.setMax(defeatBuff.pool.current);
    end
    local frameInfoCommand = ReportManager.buffToJsonString(fight, defeatBuff, 3)
    table.insert(fight.actions, frameInfoCommand);
    FightManager.playActions(frameInfoCommand)

    SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff:"
    .. buff.modelId .. " 伤害转化为护盾值: "..addHp .." , 伤害量 " .. result.damage);
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

t.New()